/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jili.ubert.clientapi.until;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jili.ubert.code.client2server.RequestPageData;
import com.panemu.tiwulfx.common.TableCriteria;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.control.TableColumn;

/**
 *
 * @author dragon
 */
public class TransferData {

    public static RequestPageData getRequestPageData(int startIndex, List<TableCriteria> filteredColumns, List<String> sortedColumns, List<TableColumn.SortType> sortingOrders, int maxResult) {
        RequestPageData rpd = new RequestPageData();
        rpd.setStartIndex(startIndex);
        rpd.setMaxResult(maxResult);
        rpd.setSortedColumns(sortedColumns);
        if (sortingOrders != null) {
            int ll = sortingOrders.size();
            List<Boolean> so = new ArrayList(ll);
            sortingOrders.stream().forEach((TableColumn.SortType o) -> {
                if (o == TableColumn.SortType.ASCENDING) {
                    so.add(true);
                } else {
                    so.add(false);
                }
            });
            rpd.setSortingOrders(so);
        }
        if (filteredColumns != null) {
            int fn = filteredColumns.size();
            byte[] so = JSON.toJSONBytes(filteredColumns, SerializerFeature.WriteDateUseDateFormat, SerializerFeature.WriteClassName, SerializerFeature.WriteEnumUsingName);
            rpd.setFilteredColumns(so);
        }
        return rpd;
    }
}
